package service

import (
	"context"
	"password-verification-management-system/dao"
	"password-verification-management-system/model"
	"password-verification-management-system/serializer"
	"password-verification-management-system/utills"
)

type UserService struct {
	ID         uint   `json:"id,omitempty" form:"id"`
	Username   string `json:"username,omitempty" form:"username"`
	Password   string `json:"password,omitempty" form:"password"`
	PublicKey  string `json:"public_key,omitempty" form:"public_key"`
	PrivateKey string `json:"private_key,omitempty" form:"private_key"`
	Status     string `json:"status,omitempty" form:"status"`
}

func (service *UserService) CreatUser(ctx context.Context) serializer.Response {
	createuserDao := dao.NewUserDao(ctx)
	err, privatefilename, publicfilename := utills.GenRsaKey(2048)
	if err != nil {
		return serializer.Response{
			Status: 400,
			Msg:    "生成公私钥文件错误",
		}
	}
	user := model.User{
		Username:   service.Username,
		Password:   service.Password,
		PublicKey:  publicfilename,
		PrivateKey: privatefilename,
		Status:     "正常",
	}
	err = createuserDao.CreateUser(&user)
	if err != nil {
		return serializer.Response{
			Status: 400,
			Msg:    "创建用户失败",
		}

	}
	return serializer.Response{
		Status: 200,
		Msg:    "创建用户成功",
	}
}

//func (service *UserService) UserLogin(ctx context.Context) interface{} {
//	loginuserDao := dao.NewUserDao(ctx)
//	loginuserDao.Callback()
//
//}
